<template>
	<view>
		<view class="my-wrap">

			<view class="my-alvelte" v-if="shows">
				<image :src="alvelte" mode=""></image>
				<text>{{nickname}}</text>
			</view>
			<view class="my-alvelte btnsss" v-if="!shows">
				<button type="default" open-type="getUserInfo" @getuserinfo="getUserInfo">
					点击登录
				</button>
			</view>

			<view class="my-alvelte-card" @click="Myguanzhu">
				<image class="back-img" src="../../static/book3.png" mode=""></image>
				<view class="my-alvelte-right">
					<text>我-的-收-藏</text>
				</view>
			</view>
			<view class="my-alvelte-card2" @click="Myalvelte">
				<view class="sty-imgs">
					<image class="back-img2" src="../../static/jing.png" mode=""></image>
				</view>
				<view class="my-alvelte-right2">
					<text>我-的-帖-子</text>
				</view>
			</view>

		</view>
		<view class="my-about">
			<view class="my-about-text">
				<view @click="Myfeedback">
					<text>意见反馈</text>
					<image src="../../static/right2.png" mode=""></image>
				</view>
				<view @click="MyAbout">
					<text>关于树洞</text>
					<image src="../../static/right2.png" mode=""></image>
				</view>
				<view @click="MyAservice">
					<text>联系客服</text>
					<image src="../../static/right2.png" mode=""></image>
				</view>
				<view @click="MyWeixin">
					<text>站主微信</text>
					<image src="../../static/right2.png" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	//引入添加用户信息
	import loning from '../../components/longin.js'
	export default {
		data() {
			return {
				shows: false,
				alvelte: '', //用户头像
				nickname: ''
			}
		},
		methods: {
			//查询数据库是否有该用户
			userinfo() {
				const db = wx.cloud.database()
				db.collection('users').get().then(res => {
					console.log(res)
					if (res.data.length != 0) {
						console.log("已经登陆")
						this.shows = true
						this.nickname = res.data[0].nickName
						this.alvelte = res.data[0].avatarUrl
					} else {
						console.log("没有登录")
						this.shows = false
					}

				}).catch(err => {
					console.log(err)
				})
			},
			getUserInfo(e) {
				console.log(e)
				let user = e.detail.userInfo
				loning(user).then(res => {
					console.log(res)
				}).catch(err => {
					console.log(err)
				})
				//刷新一下
				this.userinfo()
			},

			//跳转在我的贴子页面
			Myalvelte() {
				wx.navigateTo({
					url: '../invitation/invitation'
				})
			},
			//跳转在我的关注下面
			Myguanzhu() {
				wx.navigateTo({
					url: '../attention/attention'
				})
			},
			//跳转在用户反馈里面
			Myfeedback() {
				wx.navigateTo({
					url: '../feedback/feedback'
				})
			},
			//跳转在关于树洞里
			MyAbout() {
				wx.navigateTo({
					url: '../About/About'
				})
			},
			//跳转客服
			MyAservice(){
				wx.navigateTo({
					url: '../service/service'
				})
			},
			//跳转微信
			MyWeixin(){
				wx.navigateTo({
					url: '../owner/owner'
				})
			}
		},
		created() {
			this.userinfo()
		}
	}
</script>

<style lang="scss">
	.stys {
		list-style: none;
	}

	page {
		background-color: #ffffff;
	}

	.my-wrap {
		display: flex;
		flex-direction: column;
		align-items: center;

		.my-alvelte {
			width: 100%;
			height: 600upx;
			background-image: linear-gradient(to top, #ffffff 5%, #1995e7 100%);
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			border-bottom-right-radius: 100upx;
			border-bottom-left-radius: 100upx;

			image {
				width: 150upx;
				height: 150upx;
				border-radius: 50%;
				border: 2px solid #55aaff;
				box-shadow: 0 0 20px rgba(61, 181, 255, 0.8);
			}

			text {
				color: #515151;
				font-size: 45upx;
				margin-top: 25upx;
			}

			button {
				background-color: #63bcff;
				border-radius: 15upx;
				color: #FFFFFF;
				font-weight: bold;
				font-size: 30upx;
				padding: 10upx 30upx;
			}
		}

		.my-alvelte-card {
			position: relative;
			width: 90%;
			height: 200upx;
			background-color: #a2daff;
			border-radius: 40upx;
			margin-top: -100upx;
			display: flex;
			justify-content: center;
			align-items: center;

			.back-img {
				width: 100%;
				height: 220upx;
				opacity: 0.1;
			}

			.my-alvelte-right {
				display: flex;
				justify-content: center;
				align-items: center;
				position: absolute;

				text {
					font-size: 50upx;
					color: #ffffff;
				}

				image {
					width: 40upx;
					height: 40upx;
				}
			}
		}

		.my-alvelte-card2 {
			position: relative;
			width: 90%;
			height: 200upx;
			background-color: #ffaaff;
			border-radius: 40upx;
			margin-top: 15upx;
			display: flex;
			justify-content: center;
			align-items: center;

			.sty-imgs {
				position: relative;
				width: 100%;
				height: 100%;
				overflow: hidden;

				.back-img2 {
					transform: rotate(-60deg);
					position: absolute;
					right: 0;
					width: 300upx;
					height: 300upx;
					opacity: 0.5;

				}
			}

			.my-alvelte-right2 {
				display: flex;
				justify-content: center;
				align-items: center;
				position: absolute;

				text {
					font-size: 50upx;
					color: #000000;
				}

				image {
					width: 40upx;
					height: 40upx;
				}
			}
		}
	}

	.my-about {
		background-color: #ffffff;
		width: 100%;
		height: 300upx;

		.my-about-text {
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			view {
				display: flex;
				justify-content: space-between;
				border-bottom: 1px solid #ececec;
				padding: 40upx;

				image {
					width: 40upx;
					height: 40upx;
				}

				text {
					color: #747474;
				}
			}
		}
	}
</style>
